package com.wan.net.rpc.util;

import cn.hutool.core.util.EnumUtil;

/**
 * @author wwh
 * @date 2022/6/21 17:58
 */
public enum ResultCode {
    /**
     * 成功
     */
    SUCCESS((byte) 0),
    /**
     * 找不到指定的接口方法
     */
    SERVICE_NOT_EXIST((byte) 1, "服务不存在"),
    /**
     * 调用方法报错
     */
    INVOKE_ERROR((byte) 2,"调用方法出错")



    ;
    private final byte code;
    private final String explain;

    ResultCode(byte code, String explain) {
        this.code = code;
        if(explain == null){
            explain = this.name();
        }
        this.explain = explain;
    }

    ResultCode(byte code){
        this(code,null);
    }

    public byte getCode() {
        return code;
    }

    public String getExplain() {
        return explain;
    }

    public static ResultCode of(byte code){
        for (ResultCode resultCode : ResultCode.values()) {
            if(resultCode.getCode() == code){
                return resultCode;
            }
        }
        return null;
    }
}
